package com.bndg.blackjack

import kotlin.random.Random
/**
 * @author r
 * @date 2024/10/12
 * @description 牌桌
 */

class Deck {
    // 定义卡牌花色和点数
    private val suits = listOf("Hearts", "Diamonds", "Clubs", "Spades")
    private val ranks = listOf("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A")
    private val cards: MutableList<Card> = mutableListOf()

    private fun shuffle() {
        cards.shuffle(Random(System.currentTimeMillis()))
    }

    /**
     * 重置牌
     */
    fun resetCards() {
        cards.clear()
        for (suit in suits) {
            for (rank in ranks) {
                cards.add(Card(suit, rank))
            }
        }
        shuffle()
    }

    /**
     * 抽一张牌
     */
    fun drawCard(): Card? {
        return if (cards.isNotEmpty()) cards.removeAt(cards.size - 1) else null
    }
}